#!/usr/bin/python
# -*- coding: utf-8 -*-


import pymysql.cursors
import pymysql
import logging
import json
import sys


def getAccess():
    # print 'hello,world'
    # logging.debug(' %s', 'zhaowm')
    print "脚本名：", sys.argv[0]
    logging.debug('脚本名: %s', sys.argv[0])
    for i in range(1, len(sys.argv)):
        logging.debug('值为%s', sys.argv[i])

    uidV = '1'
    platformV = '1'
    statusV = '1'
    db = pymysql.connect('127.0.0.1', 'root', 'KeYpZrZx', 'chuanchuan')
    cursor = db.cursor(cursor=pymysql.cursors.DictCursor)
    sql = 'SELECT result FROM `tv_account` WHERE uid = %s AND platform = %s AND status =%s LIMIT 1'
    cursor.execute(sql, (uidV, platformV, statusV))
    result = cursor.fetchone()
    resultString =  result['result']
    resultDict = json.loads(resultString)
    dataDict = resultDict['data']
    print dataDict['access_token']
    logging.debug('access_token = %s', dataDict['access_token'])
    cursor.close()
    db.close()



if __name__ == "__main__":
    logging.basicConfig(level=logging.DEBUG,
                        format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',
                        datefmt='%a, %d %b %Y %H:%M:%S',
                        filename='myapp.log',
                        filemode='w')

    getAccess()
